﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>扩展控件</title>
    <link rel="stylesheet" type="text/css" href="../../Scripts/easyUI/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/easyUI/themes/icon.css" />

    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
     <script type="text/javascript" src="../../Scripts/easyUI/jquery.easyui.min.js"></script>

    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <script type="text/javascript">

        //页面启动函数.
        $(function () {

            var mypk = GetQueryString("MyPK");
            var keyOfEn = GetQueryString("KeyOfEn");
            var fk_mapData = GetQueryString("FK_MapData");
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("SQLKey", "EditFExtContral_AthList");
            handler.AddPara("Paras", "@FK_MapData=" + fk_mapData);
            var data = handler.DoMethodReturnString("SQLList");
            if (data.indexOf('err@') == 0) {
                alert(data);
            }

            data = JSON.parse(data);

            // 绑定附件列表"
            GenerBindDDL("DDL_Ath", data, "NO", "NAME");

            var mapAttr = new Entity("BP.Sys.MapAttr", mypk);

            //设置选择的模式.
            $("#RB_CtrlType_" + mapAttr.UIContralType).attr("checked", "checked");

            switch (mapAttr.UIContralType) {
                case "0":
                case "4":
                case "5":
                case "8": //手写签名版.
                case "7":
                case "10": //文本
                    break;
                case "6": //附件扩展组件..
                    $("#DDL_Ath").val(mapAttr.GetPara("AthRefObj")); //设置选择的值.
                    $("#DDL_AthShowModel").val(mapAttr.GetPara("AthShowModel")); //设置选择的值.
                    break;
                case "9": //超链接
                    var url = mapAttr.GetPara("Url");
                    url = url.replace(/[$]/g, '@');
                    $("#TB_Url").val(url); //设置URL.
                    //$("#DDL_AthShowModel").val(mapAttr.AthShowModel); //设置选择的值.
                    break;
                case "11":
                   
                    var html = "";
                    html += "<li><a href='javascript:EditImg(\""+mypk+"\")'>编辑图片</a></li>";
                    $("#FrmImg").append(html);
                    break;
                default:
                    alert('没有判断的元素.' + mapAttr.UIContralType);
                    break;
            }
        });

        

        //执行保存
        function Save() {

            var fk_mapExt = GetQueryString("MyPK");
            var frmData = $("#cc").serialize();
            var keyOfEn = GetQueryString("KeyOfEn");
            var fk_mapData = GetQueryString("FK_MapData");

            //增加附件判断
            var DDL_Ath = $("#DDL_Ath").val();
            var CtrlType = document.getElementById("RB_CtrlType_6").checked;
            if (CtrlType && null == DDL_Ath) {
                alert("该表单中没有附件，请您先在表单设计器中创建一个附件");
                return;
            }

            // var model = $("#Model").val();
            var model = $('input:radio:checked').val();

            if (model != 6 && model !=9 && model!=11) {
                var mapAttr = new Entity("BP.Sys.MapAttr", GetQueryString("MyPK"));
                mapAttr.UIContralType = model;
                mapAttr.Update();
                alert('保存成功');
                return;
            }

            //保存附件扩展的逻辑.
            if (model == 6) {

                //处理附件的保存业务逻辑相对复杂. 把这部分业务逻辑使用js实现, 并把里面的.cs的代码删除掉.
                var mapAttrAth = new Entity("BP.Sys.MapAttr", GetQueryString("MyPK"));
                mapAttrAth.UIContralType = model;
                mapAttrAth.SetPara("AthRefObj", $("#DDL_Ath").val());
                mapAttrAth.SetPara("AthShowModel", $("#DDL_AthShowModel").val());
                mapAttrAth.Update();

                //把该附件组件隐藏掉.
                var ath = new Entity("BP.Sys.FrmAttachment", $("#DDL_Ath").val());
                ath.IsVisable = 0;
                ath.Update();

                //删除该附件组件的分组.
                var group = new Entity("BP.Sys.GroupField");
                group.Delete("FrmID", GetQueryString("FK_MapData"), "CtrlID", $("#DDL_Ath").val());
                alert('保存成功');
                return;
            }

            //保存超链接
            if (model == 9) {
                var mapAttr = new Entity("BP.Sys.MapAttr", GetQueryString("MyPK"));
                mapAttr.UIContralType = model;
                mapAttr.SetPara("Url", $("#TB_Url").val().replace(/@/g,'$'));
                mapAttr.Update();

                return;
            }

            //保存图片
            if (model == 11) {
                //修改字段属性
                var mapAttr = new Entity("BP.Sys.MapAttr", GetQueryString("MyPK"));
                mapAttr.UIContralType = model;
                mapAttr.Update();
                //增加FrmImg 属性

                var frmImg = new Entity("BP.Sys.FrmUI.ExtImg");
                frmImg.MyPK = mapAttr.MyPK;
                frmImg.FK_MapData = mapAttr.FK_MapData;
                frmImg.Name = mapAttr.Name;
                frmImg.IsEdit = 1;
                frmImg.ImgAppType = 0;
                frmImg.Save();

                //保存完后编辑图片的属性
                var url = '../../Comm/EnOnly.htm?EnName=BP.Sys.FrmUI.ExtImg&PKVal=' + frmImg.MyPK;
               
                WinOpen(url);
             


            }


        }
        function EditImg(mypk) {
            var url = '../../Comm/EnOnly.htm?EnName=BP.Sys.FrmUI.ExtImg&MyPK=' + mypk;
            WinOpen(url);
        }
        function SaveAndClose() {
            Save();
            window.close();
        }

        function Close() {
            window.close();
        }

    </script>
</head>
<body>
    <form id="cc">
   
   <table>
    <caption>扩展控件</caption>
    <tr>
    <td>
  
   
    <fieldset>
        <legend>
            <input id="RB_CtrlType_0" type="radio" name="Model" value="0" /><label for="RB_CtrlType_0">不设置(使用文本框展示)</label>
        </legend>
        <ul>
            <li>不做任何设置. </li>
        </ul>
    </fieldset>

    <fieldset>
        <legend>
            <input id="RB_CtrlType_10" type="radio" name="Model" value="10" /><label for="RB_CtrlType_10">文本</label>
        </legend>
        <ul>
            <li>用于文字显示 </li>
        </ul>
    </fieldset>

    <fieldset>
        <legend>
            <input id="RB_CtrlType_9" type="radio" name="Model" value="9" /><label for="RB_CtrlType_9">超链接</label>
        </legend>
       
           
        <a href="javascript:ShowHidden('help')">自定义URL:</a>
                
            <div id="help" style="color:Gray; display:none">
            <ul>
            <li>您选择了使用外部的URL. </li>
            <li>使用外部的URL，我们提供了一个demo,您需要按照自己的格式来编写该url.</li>
            <li>该demo的位置 /SDKFlowDemo/SDKFlowDemo/PopSelectVal.htm </li>
            <li>可以使用@SDKFromServHost 变量，标识一个配置路径，该配置在web.config里设置。</li>
            </ul>
            </div>

            <input type="text" id="TB_Url" name="TB_Url" value=""  style="display:block;width:99%" />
            <br />

            宽度(px)： <input type="text" id="TB_Width" name="TB_Width"  value="" />  
            高度(px)：<input type="text" id="TB_Height" name="TB_Height"  value="" />   
            
          
    </fieldset>

     <fieldset>
        <legend>
            <input id="RB_CtrlType_8" type="radio" name="Model" value="8" /><label for="RB_CtrlType_8">手写签名版</label>
        </legend>
        <ul>
            <li>用于移动设备, PC设备的手写签名, 绘图等操作. </li>
            <li>数据会存储在: \DataUser\HandWritingImg\年月\表单ID\字段名_OID.png </li>
            <li>图片的高度，宽度与mapAttr的高度与宽度相同, 对于自由表单的x,y位置则与文本框的位置相同.</li>
        </ul>
    </fieldset>

    <fieldset>
        <legend>
            <input id="RB_CtrlType_6" type="radio" name="Model" value="6" /><label for="RB_CtrlType_6">设置为附件展示字段</label>
        </legend>
        <ul>
            <li>请选择一个附件
                <select id="DDL_Ath" name="DDL_Ath">
                </select>该附件的上传的文件数据就显示到这个控件上.</li>
            <li><a href="javascript:EditAth()">编辑附件</a></li>
            <script type="text/javascript">
                function EditAth() {
                    //增加附件判断
                    var DDL_Ath = $("#DDL_Ath").val();
                    if (null == DDL_Ath) {
                        alert("该表单中没有附件，请您先在表单设计器中创建一个附件");
                        return;
                    }
                    var ddl = document.getElementById("DDL_Ath");
                    var mypk = ddl.options[ddl.selectedIndex].value;
                    var url = '../../Comm/En.htm?EnName=BP.Sys.FrmUI.FrmAttachmentExt&MyPK=' + mypk;
                    WinOpen(url);
                }
            </script>
            <li>文件数据展示模式:
                <select id="DDL_AthShowModel" name="DDL_AthShowModel">
                    <option value="0">简洁模式. 格式: 附件(x) </option>
                    <option value="1">仅文件名称. 格式: 我的文件1.doc,我的文件2.doc </option>
                </select>
                .</li>
        </ul>
    </fieldset>
    <fieldset>
        <legend>
            <input id="RB_CtrlType_4" type="radio" name="Model" value="4" /><label for="RB_CtrlType_4">地图控件</label>
        </legend>
        <ul>
            <li>用于移动设备 </li>
        </ul>
    </fieldset>
    <fieldset>
        <legend>
            <input id="RB_CtrlType_7" type="radio" name="Model" value="7" /><label for="RB_CtrlType_7">手机拍照控件</label>
        </legend>
        <ul>
            <li>用于移动设备 </li>
        </ul>
    </fieldset>
    <fieldset>
        <legend>
            <input id="RB_CtrlType_5" type="radio" name="Model" value="5" /><label for="RB_CtrlType_5">手机录音控件</label>
        </legend>
        <ul>
            <li>用于移动设备 </li>
        </ul>
    </fieldset>
    <fieldset>
        <legend>
            <input id="RB_CtrlType_11" type="radio" name="Model" value="11" /><label for="RB_CtrlType_11">图片控件</label>
        </legend>
        <ul id="FrmImg">
            <li>用于显示图片文件 </li>
            
        </ul>
    </fieldset>
      </td>
    </tr>
   </table>

   
    <input type="button" value="保存" onclick="Save()" id="Btn_Save" name="Btn_Save" />
   
    </form>
</body>
</html>
